<template>
  <el-dialog :title="title" :visible.sync="visible" width="1300px" append-to-body>
    <div class="app-container">

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
          >新增</el-button>
        </el-col>
      </el-row>

      <el-table v-loading="loading" :data="tableData">
        <el-table-column width="300" label="目的地地接社" align="center" prop="bournReception">
          <template slot-scope="scope">
              <el-select
                placeholder="目的地地接社"
                v-model="scope.row.bournReception"
                clearable
                filterable
                value-key="orgId"
                @change="changOrg(scope.$index,$event)"
              >
                <el-option
                  v-for="item in orgList"
                  :key="item.orgId"
                  :value="item"
                  :label="item.orgName"
                >
                </el-option>
              </el-select>
          </template>
        </el-table-column>
        <el-table-column width="150" label="目的地" align="center" prop="bourn">
          <template slot-scope="scope">
              <el-select
                v-model="scope.row.bourn"
                placeholder="目的地"
                clearable
                filterable
              >
                <el-option
                  v-for="item in areaList"
                  :key="item.tourAreaId"
                  :value="item.cnName"
                  :label="item.cnName"
                >
                </el-option>
              </el-select>
          </template>
        </el-table-column>
        <el-table-column width="150" label="联系人" align="center" prop="linkman">
          <template slot-scope="scope">
            <el-input v-model="scope.row.linkman" clearable/>
          </template>
        </el-table-column>
        <el-table-column width="150" label="电话" align="center" prop="linktel">
          <template slot-scope="scope">
            <el-input v-model="scope.row.linktel" clearable />
          </template>
        </el-table-column>
        <el-table-column width="180" label="许可证" align="center" prop="licence">
          <template slot-scope="scope">
            <el-input v-model="scope.row.licence" clearable />
          </template>
        </el-table-column>
        <el-table-column width="180" label="详细地址" align="center" prop="locationInfo">
          <template slot-scope="scope">
            <el-input v-model="scope.row.locationInfo" clearable />
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" width="130">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="del(scope.$index)"
            >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">提交</el-button>
      </div>
<!--      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />-->
    </div>
  </el-dialog>
</template>

<script>
import {pageListAll,updateBourn} from "@/api/product/bourn"
import {pageListAll as areaList} from "@/api/system/tourArea"
import {pageListAll as orgList} from "@/api/system/organization"

export default {
  name: "bourn",
  components: {},
  data() {
    return {
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      visible: false,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      tableData: [],
      updateInfo:{
        productId: '',
        list:[]
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productId: '',
      },
      orgList:[],
      selectOrg:{},
      areaList:[],
      bourn:{
        bournReception: "",
        bourn: "",
        linkman: "",
        linktel: "",
        licence: "",
        locationInfo: "",
      }
    }
  },
  created() {

    //this.getList()
  },
  methods: {
    open(productId) {
      this.loading=true
      this.getEnum();
      this.queryParams.productId=productId
      this.visible = true
      this.title = "地接社列表"
      this.getList()
    },
    getList() {
      this.loading = true
      pageListAll(this.queryParams).then(response => {
          this.tableData = response.rows
          this.total = response.total
        }
      )
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    changOrg(index,org) {
      this.$set(this.tableData[index],"bournReception",org.orgName)
      this.$set(this.tableData[index],"linkman",org.linkMan)
      this.$set(this.tableData[index],"linktel",org.linkTel)
      this.$set(this.tableData[index],"licence",org.licenseKey)
      this.$set(this.tableData[index],"locationInfo",org.registerTel)
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    handleAdd() {
      this.tableData.push(this.bourn)
    },
    del(index) {
      this.tableData.splice(index,1)
    },
    getEnum() {
      orgList({}).then(response => {
        this.orgList=response.rows
        this.loading=false
      })
      areaList({}).then(response => {
        this.areaList=response.rows
      })
    },
    submitForm() {
      this.loading = true
      this.updateInfo.productId=this.queryParams.productId
      this.updateInfo.list=this.tableData
      updateBourn(this.updateInfo).then(response => {
        this.$modal.msgSuccess("修改成功")
        this.visible = false
        this.getList()
      })
    },
  }
}
</script>
